package com.laiyima.zhongjiang.linghuilv.demo.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.bean.MachineBean;

import java.util.List;

public class MachineAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<MachineBean> mMachineBean;
     public MachineAdapter(Context context, List<MachineBean> maxMachineBeanDatas){
        mContext = context;
        mInflater = LayoutInflater.from(context);
         mMachineBean = maxMachineBeanDatas;
    }
    @Override
    public int getCount() {
        return mMachineBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mMachineBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.machine_item,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.machine_sn = convertView.findViewById(R.id.machine_sn);
            viewHolder.machine_lId = convertView.findViewById(R.id.machine_zld);
            viewHolder.machine_nid = convertView.findViewById(R.id.machine_nid);
            viewHolder.machine_merName = convertView.findViewById(R.id.machine_name);
            viewHolder.machine_state = convertView.findViewById(R.id.machine_state);
            viewHolder.machine_mobile = convertView.findViewById(R.id.machine_mobile);
            convertView.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        MachineBean mymachineBean = mMachineBean.get(position);
        viewHolder.machine_sn.setText("SN:  "+mymachineBean.getSn());
        viewHolder.machine_lId.setText(mymachineBean.getzId());
        viewHolder.machine_nid.setText(mymachineBean.getNid());
        viewHolder.machine_merName.setText(mymachineBean.getMerName());
        viewHolder.machine_state.setText(mymachineBean.getState());
        viewHolder.machine_mobile.setText(mymachineBean.getMobile());

        if(mymachineBean.getState().equals("已使用")){
            viewHolder.machine_state.setTextColor(Color.parseColor("#108E23"));
        }else{
            viewHolder.machine_state.setTextColor(Color.parseColor("#D0021B"));
        }

        return convertView;
    }
    public static class ViewHolder{
        TextView machine_sn;
        TextView machine_lId;
        TextView machine_nid;
        TextView machine_merName;
        TextView machine_state;
        TextView machine_mobile;

    }
}
